﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace CaiBaby.Common
{
    public static class RecordLog
    {
        public static void WriteError(string msg)
        {
            DateTime dt = DateTime.Now;
            string path = System.AppDomain.CurrentDomain.BaseDirectory +"Log\\Error";
            string filename = path + "\\" + (dt.Year * 10000 + dt.Month * 100 + dt.Day).ToString() + ".txt";
            while (true)
            {
                try
                {
                    if (!Directory.Exists(path))
                        Directory.CreateDirectory(path);
                    if (!File.Exists(filename))
                        File.Create(filename);

                    using (StreamWriter sw = new StreamWriter(filename, true))
                    {
                        string txt ="ERROR " + dt.ToString("yyyy-MM-dd HH:mm:ss:fff") + "：" + msg;
                        sw.WriteLine(txt);
                    }

                    break;
                }
                catch { }
            }
        }

        public static void WriteLog(string msg)
        {
            DateTime dt = DateTime.Now;
            string path = System.AppDomain.CurrentDomain.BaseDirectory + "\\Log\\Event";
            string filename = path + "\\" + (dt.Year * 10000 + dt.Month * 100 + dt.Day).ToString() + ".txt";
            while (true)
            {
                try
                {
                    if (!Directory.Exists(path))
                        Directory.CreateDirectory(path);
                    if (!File.Exists(filename))
                        File.Create(filename);

                    using (StreamWriter sw = new StreamWriter(filename, true))
                    {
                        string txt ="INFOS " + dt.ToString("yyyy-MM-dd HH:mm:ss:fff")+"：" + msg ;
                        sw.WriteLine(txt);
                    }

                    break;
                }
                catch { }
            }
        }
    }
}
